<?php
    $links = base64_decode($_GET['file']);
    
    $link = explode("|", $links);
    $filename=$link[0];
    $filerealname=$link[1];
    
    $file_extension = end(explode('.', $filename));

    if( $filename == "" ) 
    {
        $error = true;
        exit($error);
    } elseif ( ! file_exists( $filename ) ) 
    {
        $error = true;
        exit($error);
    };

    switch( $file_extension )
    {
        case "pdf": $ctype="application/pdf"; break;
        case "exe": $ctype="application/octet-stream"; break;
        case "zip": $ctype="application/zip"; break;
        case "doc": $ctype="application/msword"; break;
        case "xls": $ctype="application/vnd.ms-excel"; break;
        case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
        case "gif": $ctype="image/gif"; break;
        case "png": $ctype="image/png"; break;
        case "jpeg":
        case "jpg": $ctype="image/jpg"; break;
        default: $ctype="application/force-download";
    }

    header('Content-Description: File Transfer');
    header("Content-Type: $ctype");
    header("Content-Disposition: attachment; filename=$filerealname.$file_extension" );
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filename));
    ob_clean();
    flush();
    readfile($filename);
    exit;

?>
